package com.hat.cxt.base;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

import com.classic.common.MultipleStatusView;

/**
 * Created by Administrator on 2018/4/25.
 */

public abstract class BaseActivity extends AppCompatActivity {

    /**
     * 多种状态的 View 的切换
     */
    protected MultipleStatusView mLayoutStatusView;
//    protected MultipleStatusView mLayoutStatusView: MultipleStatusView? = null;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(LayoutId());
        initView();
        initData();
        initListener();
    }

    //加载布局
    public abstract Integer LayoutId();
    //初始化数据
    public abstract void initData();
    //初始化视图
    public abstract void initView();
    //监听数据
    public void initListener(){
        if(mLayoutStatusView==null){
            mLayoutStatusView = new MultipleStatusView(this);
            mLayoutStatusView.setOnClickListener(View -> start());
        }
    }

//    public View.OnClickListener mRetryClickListener = new View.OnClickListener(){
//
//        @Override
//        public void onClick(View v) {
//                start();
//        }
//    };

    //开始请求
    public abstract void start();


    //打开软键盘
    public void openKeyBord(EditText mEditText, Context mContext){
        InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(mEditText, InputMethodManager.RESULT_SHOWN);
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);

    }

    //关闭软键盘
    public void closeKeyBord(EditText mEditText, Context mContext){
        InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(mEditText.getWindowToken(),0);
    }


}
